package com.boang.bank;

import java.util.HashMap;
import java.util.Hashtable;

/*
@author: DELL
@date: 2024/11/29 17:01
*/
public class BankAccount {
    private String ID;
    private int balance;
    public HashMap <String,Integer> map;
    public BankAccount() {
        map=new HashMap<String,Integer>();
        map.put("123",5000);
        map.put("456",6000);
        map.put("789",8000);
    }
    public BankAccount(String ID,int balance) {
        this.ID = ID;
        this.balance = balance;
    }
    public String getID() {
        return ID;
    }
    public void setID(String ID) {
        this.ID = ID;
    }
    public int getBalance() {
        return balance;
    }
    public void setBalance(int balance) {
        this.balance = balance;
    }
    public synchronized void deposit(int money,String Id){
        int i = map.get(Id);
        try{
           if (money>i){
               throw new InsufficientFundsException("超出额度");
           }else{
             i=i -money;
             map.put(Id,i);
           }
         }catch(InsufficientFundsException e){
             System.out.println(e.getMessage());
        }
    }
    public synchronized void save(String Id,int money){
     int i=map.get(Id)+money;
     map.put(Id,i);
    }
}
